<!-- 修改说明：多仓库修改  t  2019-11-13
	15-23	支持多仓库：从session中获取仓库id
-->
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>提示记录</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<jsp:include page="${pageContext.request.contextPath }/resource_path.jsp" flush="true"/>
<!-- ******************************多仓库修改  t  2019-11-13 开始*************************** -->
	<!-- 从session中获取仓库id -->
	<% Long warehouseId =  (Long)request.getSession().getAttribute("warehouse_id"); 
	  String warehouse_id = "";
		if(warehouseId != null){
		  warehouse_id = String.valueOf(warehouseId);
	  }
	%>
<!-- ******************************多仓库修改  t  2019-11-13 结束*************************** -->
</head>
<body class="layui-anim layui-anim-up">
	<!-- ******************************多仓库修改  t  2019-11-13 开始*************************** -->
	<!-- 利用全局仓库id的input保存session中仓库id -->
	<input id="warehouse_id" hidden="hidden" value="<%=warehouse_id%>">
	<!-- ******************************多仓库修改  t  2019-11-13 结束*************************** -->	
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a>
          <cite>已收货未上架提示记录</cite>
        </a>
      </span>
    </div>
    <div class="x-body">
      <div style="margin-bottom: 18px">
		<div class="layui-inline">
			<table>
				<tr>
					<td>
						<input class="layui-input" name="keyword01" id="keyword01" placeholder="请输入收货单号" autocomplete="off" style="display: inline; width: 180px; margin-left: 10px">
					</td>
					<td>
						<input class="layui-input" name="keyword02" id="keyword02" placeholder="请输入SAP" autocomplete="off" style="display: inline; width: 180px; margin-left: 10px"> 
					</td>
					<td>
						<input class="layui-input" id="startTime" placeholder="请输入开始时间" autocomplete="off" style="display: inline; width: 180px; margin-left: 10px">
						-<input class="layui-input" id="endTime" placeholder="请输入结束时间" autocomplete="off" style="display: inline; width: 180px; margin-left: 10px"> 
					</td>
				</tr>
			</table>
		</div>
		<button class="layui-btn layui-btn-normal" data-type="reload"><i class="layui-icon">&#xe615;</i>检索</button>
	  	<!-- ******************************优化添加导出  t  2019-11-14 开始*************************** -->
        <div style="display:none;">
        	<table class="layui-hide" id="tableListExcel" lay-filter="tableListExcel"></table>
        </div>
        <button class="layui-btn layui-btn-danger" data-type="doExcel"><i class="layui-icon layui-icon-upload-drag"></i>导出</button>		</div>
        <!-- ******************************优化添加导出  t  2019-11-14 开始*************************** -->
	  </div>
	  <table class="layui-hide" id="tableList" lay-filter="tableList"></table>
	  <table class="layui-hide" id="tableDetails1" lay-filter="tableDetails1"></table>
	</div>

	<script type="text/javascript">
        var table;
		layui.use(['table','layer','upload','form','laydate'], function(){
			table = layui.table;
			var layer = layui.layer;
			var form = layui.form;
			
			var laydate = layui.laydate;
			var excel = layui.excel;
			//日期时间范围
			var minListDate = "1000-01-01 00:00:00";//最小可选时间，例：1990-02-01
		    var maxListDate = "3000-12-31 23:59:59";//最大可选时间，例：2200-12-31   
		    var enddate = laydate.render({
		        elem: "#endTime",
		        format: 'yyyy-MM-dd HH:mm:ss',
		        type: 'datetime',
		        min: minListDate,
		        max: maxListDate,
		        done: function (val, date) {
		            if (date && date.year){
		            	//设置结束时间 设置开始时间的最大值为结束时间
		                begindate.config.max = {
		                    year: date.year,
		                    month: date.month - 1,//必须减1才是正确值
		                    date: date.date,
		                    hours: date.hours,
		                    minutes: date.minutes,
		                    seconds: date.seconds
		                };
		            }else {
		            	//清除结束值    设置开始时间最大值
		                var dateInit = new Date(maxListDate.replace(/-/g, "/"));
		                begindate.config.max = {
		                    year: dateInit.getFullYear(),
		                    month: dateInit.getMonth(),
		                    date: dateInit.getDate(),
		                    hours: dateInit.getHours(),
		                    minutes: dateInit.getMinutes(),
		                    seconds: dateInit.getSeconds()
		                };
		            }
		        }
		    });
		    var begindate = laydate.render({
		        elem: "#startTime",
		        format: 'yyyy-MM-dd HH:mm:ss',
		        type: 'datetime',
		        min: minListDate,
		        max: maxListDate,
		        done: function (val, date) {
		            if (date && date.year){
		            	//设置开始时间 设置结束时间的最小值为开始时间
		                enddate.config.min = {
		                    year: date.year,
		                    month: date.month - 1,
		                    date: date.date,
		                    hours: date.hours,
		                    minutes: date.minutes,
		                    seconds: date.seconds
		                };
		            }else {
		            	//清除开始值 ，设置结束值最小值
		                var dateInit = new Date(minListDate.replace(/-/g, "/"));
		                enddate.config.min = {
		                    year: dateInit.getFullYear(),
		                    month: dateInit.getMonth(),
		                    date: dateInit.getDate(),
		                    hours: dateInit.getHours(),
		                    minutes: dateInit.getMinutes(),
		                    seconds: dateInit.getSeconds()
		                };
		            }
		        }
		    });
			
			var $ = layui.jquery, active = {
				reload:function () {
					var keyword01 = $.trim($("#keyword01").val());
	                var keyword02 = $.trim($("#keyword02").val());
	                var tuisongtime = "";
	                var startTime = $.trim($("#startTime").val());
					if(startTime != null && startTime != ""){
						var tuisongtime = tuisongtime + " and tuiSongTime >= '"+startTime+"' ";
					}
					var endTime = $.trim($("#endTime").val());
					if(endTime != null && endTime != ""){
						var tuisongtime = tuisongtime + " and tuiSongTime <= '"+endTime+"' ";
					}
					/* ******************************多仓库修改  t  2019-11-13 开始*************************** */
					//判断全局仓库id是否为空  不为空加入查询条件
					var warehouse_id = $.trim($("#warehouse_id").val());
					if(warehouse_id != null && warehouse_id != ""){
						var tuisongtime = tuisongtime + " and warehouse_id = '"+warehouse_id+"' ";
					}
					/* ******************************多仓库修改  t  2019-11-13 结束*************************** */
					table.reload('tableList',{
						method:'get'
						,where:{
							sendNumber:keyword01
	                        ,sap:keyword02
	                        ,tuisongtime:tuisongtime
						}
						,page: {
		                    curr: 1//重新从第 1 页开始
		                }
					});
				},
				/* ******************************优化添加导出  t  2019-11-14 开始*************************** */
	            doExcel:function () {
	            	var keyword01 = $.trim($("#keyword01").val());
	                var keyword02 = $.trim($("#keyword02").val());
	                var tuisongtime = "";
	                var startTime = $.trim($("#startTime").val());
					if(startTime != null && startTime != ""){
						var tuisongtime = tuisongtime + " and r.tuiSongTime >= '"+startTime+"' ";
					}
					var endTime = $.trim($("#endTime").val());
					if(endTime != null && endTime != ""){
						var tuisongtime = tuisongtime + " and r.tuiSongTime <= '"+endTime+"' ";
					}
					//判断全局仓库id是否为空  不为空加入查询条件
					var warehouse_id = $.trim($("#warehouse_id").val());
					if(warehouse_id != null && warehouse_id != ""){
						var tuisongtime = tuisongtime + " and r.warehouse_id = '"+warehouse_id+"' ";
					}
	                $.ajax({
	                    url: '${pageContext.request.contextPath }/receiveTips/selectAllByReceiveTips.do',
	                    dataType: 'json',
	                    data: {
	                    	sendNumber:keyword01
	                        ,sap:keyword02
	                        ,tuisongtime:tuisongtime
	                    },
	                    success: function(data) {
	                        if(data.length > 0){
	                        	/* var exportData1 = [];
	                        	exportData1 = excel.filterExportData(data,{
	                        	                                    sendNumber:'receiveTips.sendNumber'
	                        	                                    ,sendDate:'receiveTips.sendDate'
	                        	                                    ,sap:'receiveTips.sap'
	                        	                                    ,tuisongtime:'receiveTips.tuisongtime'
	                        	                                    ,codenum:'receiveTips.codenum'
	                        	                                    ,code:'code'}) */
	                        	var exportData = [];
	                        	data.forEach(function(item){
	                        		exportData.push({sendNumber:item.receiveTips.sendNumber
	                                    ,sendDate:item.receiveTips.sendDate
    	                                    ,sap:item.receiveTips.sap
    	                                    ,tuisongtime:item.receiveTips.tuisongtime
    	                                    ,codenum:item.receiveTips.codenum
    	                                    ,code:item.code})
								})
	                        	//data.unshift({'receiveTips.sendNumber': '收货单号','receiveTips.sendDate':'收货时间','receiveTips.sap':'SAP','receiveTips.tuisongtime':'推送时间','receiveTips.codenum':'已收货未上架数量',code:'条码'});
								exportData.unshift({sendNumber: '收货单号',sendDate:'收货时间',sap:'SAP',tuisongtime:'推送时间',codenum:'已收货未上架数量',code:'条码'});
	                        	 excel.exportExcel({
	                                 sheet1: exportData}, '已收货未上架提示记录.xlsx', 'xlsx');
	                        	/* table.reload('tableListExcel',{
	                        		data:data
	                        	}) */
	                        	//table.exportFile(ins1.config.id,data, 'xls');
	                        	
	                        }else{
	                        	toastr.warning("数据为空不能导出！");
	                        }
	                    },
	                    error:function(res){
	                    	toastr.error("导出失败！");
	                    }
	                });
	            }
	            /* ******************************优化添加导出  t  2019-11-14 结束*************************** */
			}
			$('.layui-btn').on('click', function(){
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			});
			/* ******************************多仓库修改  t  2019-11-11 开始*************************** */
			var tuisongtime = ""
			//判断全局仓库id是否为空  不为空加入查询条件
			/* var warehouse_id = $.trim($("#warehouse_id").val());
			if(warehouse_id != null && warehouse_id != ""){
				tuisongtime = tuisongtime + " and warehouse_id = '"+warehouse_id+"' ";
			} */
			//不执行检索或点击时页面默认无信息
			tuisongtime = tuisongtime + " and warehouse_id = '-1' ";
			/* ******************************多仓库修改  t  2019-11-11 结束*************************** */
			table.render({
				elem: '#tableList'
                ,url:'${pageContext.request.contextPath }/receiveTips/list.do'
               	,where:{
                       tuisongtime:tuisongtime
				}
				,toolbar: '#toolbar'
				,title: 'machineList'
				,limits:[10,20,30]
                ,defaultToolbar:['filter', 'print']
				,request: {   //如果无需自定义请求参数，可不加该参数
	                pageName: 'page' //页码的参数名称，默认：page
	                ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
	            }
	            ,response: {   //如果无需自定义数据响应名称，可不加该参数
	                countName: 'total' //规定数据总数的字段名称，默认：count
	                ,dataName: 'rows' //规定数据列表的字段名称，默认：data
	            }
				,cols: [
		                [{
		                    type: 'checkbox',
		                    fixed: 'left'
		                }, {
		                	field:'id',
		                	title:'序号', 
		                	sort: true,
		                	width: 60,
		                	type:'numbers',
		                	align:'center'
		                } , {
		                    field: 'sendNumber',
		                    title: '收货单号',
		                    align:'center',
		                } , {
		                    field: 'sendDate',
		                    title: '收货时间',
		                    align:'center',
		                } , {
		                    field: 'sap',
		                    title: 'SAP',
		                    align:'center',
		                } , {
		                    field: 'tuisongtime',
		                    title: '推送时间',
		                    align:'center',
		                }, {
		                    field: 'codenum',
		                    title: '已收货未上架数量',
		                    align:'center',
		                }
		                ]
		               ]
				,page: true
				,done : function(){
	                $('th').css({
	                    'background-color': '#009688', 'color': '#fff','font-weight':'bold',
	                    //'font-size': 10,
	                })
	            }
			});
			
			
        	//表格
            table.render({
                elem: '#tableDetails1'
                ,url:'${pageContext.request.contextPath }/receiveTipsDetails/list.do?rtid='+"-1"
                ,title: '已收货未上架提示'
                ,limits:[10,20,30]
                ,defaultToolbar:['filter', 'print']
                ,request: {   //如果无需自定义请求参数，可不加该参数
                    pageName: 'page' //页码的参数名称，默认：page
                    ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
                }
                ,response: {   //如果无需自定义数据响应名称，可不加该参数
                    countName: 'total' //规定数据总数的字段名称，默认：count
                    ,dataName: 'rows' //规定数据列表的字段名称，默认：data
                } 
                ,cols: [
                    [{
                        field: 'id',
                        title: 'id',
                        hide:true //是否初始隐藏列，默认：false。layui 2.4.0 新增
                    }, {
                    	field:'id',
                    	title:'序号', 
                    	sort: true,
                    	width: 60,
                    	type:'numbers',
                    	align:'center'
                    } , {
                    	field: 'code',
                        title: '条码',
                        align:'center',
                    }
                    ]]
                ,page: true
                ,done : function(){
	                $('th').css({
	                    'background-color': '#009688', 'color': '#fff','font-weight':'bold',
	                    //'font-size': 10,
	                })
	            } 
                //,height: 500
            });
        	
	        table.on('row(tableList)', function(obj){
	        	var data = obj.data;
	        	table.reload('tableDetails1',{
						url:'${pageContext.request.contextPath }/receiveTipsDetails/list.do?rtid='+data.id
						,method:'get'
						,page: {
			                curr: 1//重新从第 1 页开始
			            }
        	  	});
	        	if(obj.checked == true && obj.type == 'all'){
	                //点击全选
	                $('.layui-table-body table.layui-table tbody tr').addClass('layui-table-click');
	            }else if(obj.checked == false && obj.type == 'all'){
	                //点击全不选
	                $('.layui-table-body table.layui-table tbody tr').removeClass('layui-table-click');
	            }else if(obj.checked == true && obj.type == 'one'){
	                //点击单行
	                if(obj.checked == true){
	                    obj.tr.addClass('layui-table-click');
	                }else{
	                    obj.tr.removeClass('layui-table-click');
	                }
	            }else if(obj.checked == false && obj.type == 'one'){
	                //点击全选之后点击单行
	                if(obj.tr.hasClass('layui-table-click')){
	                    obj.tr.removeClass('layui-table-click');
	                }
	            }
	        });
		});
		
		//获取当前时间生成的编码
	   	function curentTimeNumber() {
	   		var now=new Date();
	   		var year = now.getFullYear();       //年
	   	    var month = now.getMonth() + 1;     //月
	   	    var day = now.getDate();            //日
	   	 	var hours = now.getHours(); //获取当前小时数(0-23)
		   	var minutes = now.getMinutes(); //获取当前分钟数(0-59)
		   	var seconds = now.getSeconds(); //获取当前秒数(0-59)
	   	    //var mill=now.getMilliseconds();
	   	    var time=year+""+add0(month)+""+add0(day)+""+add0(hours)+""+add0(minutes)+""+add0(seconds);
	   		return time;
	   	}
	    //获取当前日期
	   	function curentTime() {
	   		var now=new Date();
	   		var year = now.getFullYear();       //年
	   	    var month = now.getMonth() + 1;     //月
	   	    var day = now.getDate();            //日
	   	    var time=year+"-"+add0(month)+"-"+add0(day);
	   		return time;
	   	}
	   	function add0(m){return m<10?'0'+m:m }
		toastrStyle()
	</script>
</body>
</html>